package com.yunji.web.base;

import com.yunji.base.business.SiteAuditBusiness;
import com.yunji.base.dto.SiteAuditDTO;
import com.yunji.base.params.SiteAuditParam;
import com.yunji.base.enums.AuditStatus;
import com.yunji.base.vo.SiteAuditVO;
import com.yunji.common.base.response.Response;
import com.yunji.common.base.response.ResponseHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@Api(tags = "管理端-网点审核管理")
@RequestMapping("/container/siteAudit")
public class SiteAuditController {

    @Resource
    SiteAuditBusiness business;

    @ApiOperation("查询网点审核列表(不包含详情)")
    @GetMapping("/list")
    public Response<List<SiteAuditVO>> list(@Valid SiteAuditParam param)
    {
        return ResponseHelper.successWithPage(business.search(param), param.getTotal());
    }

    @ApiOperation("查看网点审核详细")
    @PreAuthorize("@ss.hasPermi('container:site:log')")
    @GetMapping("/{auditId}")
    public Response<SiteAuditVO> getInfo(@PathVariable("auditId") Long auditId){
        return ResponseHelper.success(business.getInfo(auditId));
    }

    @ApiOperation("审核通过")
    @GetMapping(value = "acceptAudit")
    public Response<String> acceptAudit(@RequestParam(name = "auditId") Long auditId)
    {
        business.audit(auditId, AuditStatus.ACCEPT.getCode(), null);
        return ResponseHelper.success("提交成功");
    }

    @ApiOperation("审核驳回")
    @GetMapping(value = "rejectAudit")
    public Response<String> rejectAudit(@RequestParam(name = "auditId") Long auditId, @RequestParam("reason") String reason)
    {
        business.audit(auditId, AuditStatus.REJECT.getCode(), reason);
        return ResponseHelper.success("提交成功");
    }

    @ApiOperation("取消申请")
    @GetMapping(value = "cancel")
    @PreAuthorize("@ss.hasPermi('container:site:back')")
    public Response<String> cancel(@RequestParam(name = "auditId") Long auditId){
        return ResponseHelper.handle(business.cancel(auditId),"取消失败");
    }

    @ApiOperation("重新提交")
    @PostMapping(value = "commit")
    @PreAuthorize("@ss.hasPermi('container:site:afresh')")
    public Response<String> commit(@RequestBody SiteAuditDTO dto){
        business.commit(dto);
        return ResponseHelper.success("提交成功");
    }


}
